axios.defaults.baseURL = 'https://hmajax.itheima.net'

// 请求拦截器
axios.interceptors.request.use(function (config) {
    const token = localStorage.getItem('token')
    if (token) {
      config.headers['Authorization'] = token
    }
    return config;
  }, function (error) {
    return Promise.reject(error);
  })
  
//  响应拦截器
axios.interceptors.response.use(function (response) {
    return response;
  }, function (err) {

    if(err.response.status == 401){
        pxmu.toast('登陆过期，请重新登陆')
        setTimeout(function(){
            location.href = './login.html'
        },2000)
    }
    return Promise.reject(err)
  })